/**
 * 
 */
package com.jonosoft.photocast.viewer.web.client.photocast;

import java.util.Date;

import com.google.gwt.json.client.JSONNumber;
import com.google.gwt.json.client.JSONObject;
import com.google.gwt.json.client.JSONString;
import com.google.gwt.user.client.rpc.IsSerializable;

/**
 * TODO Add description PhotocastObject (com.jonosoft.photocast.viewer.web.client.PhotocastObject)
 *
 * @author jon
 *
 */
public abstract class PhotocastObject implements IsSerializable {
	
	protected JSONObject jsonRep = null;
	
	protected static final String EMPTY = "";
	
	protected static final String JSONStringValueOrNull(JSONString jsonString) {
		if (jsonString != null)
			return jsonString.stringValue();
		else
			return null;
	}
	
	protected static final Double JSONNumberValueOrNull(JSONNumber jsonNumber) {
		if (jsonNumber != null)
			return new Double(jsonNumber.getValue());
		else
			return null;
	}
	
	protected static final Long JSONLongValueOrNull(JSONNumber jsonNumber) {
		Double dbl = JSONNumberValueOrNull(jsonNumber);
		
		if (dbl != null)
			return new Long(dbl.longValue());
		else
			return null;
	}
	
	protected static final Date DateValueOrNull(JSONString jsonString) {
		String dateString = JSONStringValueOrNull(jsonString);
		
		if (dateString != null)
			return new Date(dateString);
		else
			return null;
	}
	
	public void setJSONRepresentation(JSONObject jsonRep) {
		this.jsonRep = jsonRep;
	}
	
	public JSONObject getJSONRepresentation() {
		return jsonRep;
	}
	
}
